package com.sskj.mine;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.bean.ImgHighBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.SettingActivity;

import java.io.File;


/**
 * @author Hey
 * Create at  2019/05/03
 */
class SettingPresenter extends BasePresenter<SettingActivity> {
    // 跟新头像
    public void submitVerify(File file) {
        OkGo.<HttpData<ImgHighBean>>post(HttpConfig.BASE_URL + HttpConfig.HIGH_VERIFY_IMG)
                .isMultipart(false)
                .params("file", file)
                .execute(new JsonCallBack<HttpData<ImgHighBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<ImgHighBean>> response) {
                        HttpData body = response.body();
                        if (body.status == HttpConfig.OK) {
                            ToastUtil.showShort(body.msg);
                            ImgHighBean hignBean = (ImgHighBean) body.getData();
                            chooseImg(((ImgHighBean) body.getData()).getUrl());
                        }
                    }
                });
    }


    public void chooseImg(String fileUrl) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.CHOOSE_IMG)
                .isMultipart(false)
                .params("upic", fileUrl)
                .execute(new JsonCallBack<HttpData<Object>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
                        HttpData body = response.body();
                        if (body.status == HttpConfig.OK) {
                            ToastUtil.showShort(body.msg);
                            mView.updateUi();
                        }
                    }
                });
    }
}
